package com.xuqm.sdhbwfu.app.ui

import android.content.Intent
import android.os.Bundle
import com.xuqm.base.adapter.BasePagedAdapter
import com.xuqm.base.adapter.CommonPagedAdapter
import com.xuqm.base.adapter.ViewHolder
import com.xuqm.base.ui.BaseListFormLayoutActivity
import com.xuqm.sdhbwfu.app.R
import com.xuqm.sdhbwfu.app.databinding.ActivityRiskListBinding
import com.xuqm.sdhbwfu.app.model.ItemRiskList
import com.xuqm.sdhbwfu.app.viewmodel.RiskListViewModel
import com.xuqm.sdhbwfu.core.extensions.addItemDecorationForVertical

class RiskListActivity :
    BaseListFormLayoutActivity<ItemRiskList, RiskListViewModel, ActivityRiskListBinding>() {

    override fun getLayoutId(): Int = R.layout.activity_risk_list
    override fun fullscreen(): Boolean = true

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        binding.riskAdd.setOnClickListener {
            startActivity(Intent(mContext, RiskCreateActivity::class.java))
        }
        binding.inspectionBackLyt.setOnClickListener { finish() }
        binding.baseRecyclerView.addItemDecorationForVertical(10)


    }

    override fun initData() {
        super.initData()
        viewModel.status.observe(this) {
            binding.riskNumTv.text = viewModel.data.size.toString()
        }
    }

//    override fun onResume() {
//        super.onResume()
//        viewModel.invalidate()
//    }

    override fun adapter(): BasePagedAdapter<ItemRiskList> = adapters

    private val adapters =
        object : CommonPagedAdapter<ItemRiskList>(R.layout.item_risk_list) {
            override fun convert(holder: ViewHolder, item: ItemRiskList, position: Int) {
                holder.setText(R.id.item_job_no, item.workOrderNum)
                holder.setText(R.id.item_job_name, item.title)
                holder.setText(R.id.item_job_obj, item.applyUserName)
                holder.setText(R.id.item_job_type, item.createTime)

                holder.setClickListener(R.id.item_job_num) {
                    startActivity(Intent(mContext, RiskTodoActivity::class.java).apply {
                        putExtra("workNum", item.workOrderNum)
                    })
                }
            }

        }
}